package com.macrosoftinc.feedreaderxtreme.activity;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.ListFragment;
import android.support.v4.view.ViewPager;

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
import com.macrosoft.frpd.utils.Logger;
import com.macrosoftinc.feedreaderxtreme.fragments.LeftMenuListFragment;
import com.macrosoftinc.feedreaderxtreme.R;
import com.slidingmenu.lib.SlidingMenu;
import com.slidingmenu.lib.app.SlidingFragmentActivity;

public class BaseActivity extends SlidingFragmentActivity {

	private ListFragment expandList;

	private int mTitleRes;
	protected LeftMenuListFragment mFrag;

	public BaseActivity(int titleRes) {
		mTitleRes = titleRes;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		Logger.i("onCreate()" + this.getClass().getSimpleName());
		
//		requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

		setTitle(mTitleRes);
		// set the Behind View
		setBehindContentView(R.layout.menu_frame);
		FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();

		mFrag = new LeftMenuListFragment();
		t.replace(R.id.menu_frame, mFrag);
		t.commit();

		// customize the SlidingMenu
		SlidingMenu sm = getSlidingMenu();
		sm.setShadowWidthRes(R.dimen.shadow_width);
		sm.setShadowDrawable(R.drawable.shadow);
		sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
		sm.setFadeDegree(0.35f);
		sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

		getSupportActionBar().setDisplayHomeAsUpEnabled(true);

	}

	// @Override
	// public boolean onCreateOptionsMenu(Menu menu) {
	// // Inflate your menu.
	// getSupportMenuInflater().inflate(R.menu.activity_main, menu);
	//
	// // Set file with share history to the provider and set the share intent.
	// MenuItem actionItem = menu.findItem(R.id.menu_share);
	// ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
	// actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
	// // Note that you can set/change the intent any time,
	// // say when the user has selected an image.
	// actionProvider.setShareIntent(createShareIntent());
	//
	// // XXX: For now, ShareActionProviders must be displayed on the action bar
	// // Set file with share history to the provider and set the share intent.
	// // MenuItem overflowItem = menu.findItem(R.id.menu_item_share_action_provider_overflow);
	// // ShareActionProvider overflowProvider =
	// // (ShareActionProvider) overflowItem.getActionProvider();
	// // overflowProvider.setShareHistoryFileName(
	// // ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
	// // Note that you can set/change the intent any time,
	// // say when the user has selected an image.
	// // overflowProvider.setShareIntent(createShareIntent());
	//
	// return true;
	// }

	// private Intent createShareIntent() {
	// Intent shareIntent = new Intent(Intent.ACTION_SEND);
	// shareIntent.setType("drawable/*");
	// Uri uri = Uri.fromFile(getFileStreamPath("group_down.png"));
	// shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
	// return shareIntent;
	// }

//	@Override
//    public boolean onCreateOptionsMenu(Menu menu) {
//       MenuInflater inflater = getSupportMenuInflater();
//       inflater.inflate(R.menu.activity_main, menu);
//       return super.onCreateOptionsMenu(menu);
//    }
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			toggle();
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	public class BasePagerAdapter extends FragmentPagerAdapter {
		private List<Fragment> mFragments = new ArrayList<Fragment>();
		private ViewPager mPager;

		public BasePagerAdapter(FragmentManager fm, ViewPager vp) {
			super(fm);
			mPager = vp;
			mPager.setAdapter(this);
			for (int i = 0; i < 3; i++) {
				addTab(new LeftMenuListFragment());
			}
		}

		public void addTab(Fragment frag) {
			mFragments.add(frag);
		}

		@Override
		public Fragment getItem(int position) {
			return mFragments.get(position);
		}

		@Override
		public int getCount() {
			return mFragments.size();
		}
	}

}
